//
// Created by Administrator on 2022/10/10.
//

#ifndef HTTPSERVER_HTTP_REQUEST_H
#define HTTPSERVER_HTTP_REQUEST_H

#include <dts.h>
#include <hash_util.h>
#include "lstring.h"
// http请求类型数量
#define REQ_TYPE_NUM 10

#define HEADER_END_TARGET_LEN 4
#define HEADER_END_TARGET "\r\n\r\n"

#define HEADER_LINE_END_TARGET_LEN 2
#define HEADER_LINE_END_TARGET "\R\N"

#define HTTP_UNKNOWN                    0x00000001
#define HTTP_POST                       0x00000002
#define HTTP_GET                        0x00000004
#define HTTP_HEAD                       0x00000008
#define HTTP_PUT                        0x00000010
#define HTTP_PATCH                      0x00000020
#define HTTP_OPTIONS                    0x00000040
#define HTTP_DELETE                     0x00000080
#define HTTP_CONNECT                    0x00000100
#define HTTP_TRACE                      0x00000200

#define HTTP_CONTINUE                  100
#define HTTP_SWITCHING_PROTOCOLS       101
#define HTTP_PROCESSING                102
#define HTTP_OK                        200
#define HTTP_CREATED                   201
#define HTTP_ACCEPTED                  202
#define HTTP_NO_CONTENT                204
#define HTTP_PARTIAL_CONTENT           206
#define HTTP_SPECIAL_RESPONSE          300
#define HTTP_MOVED_PERMANENTLY         301
#define HTTP_MOVED_TEMPORARILY         302
#define HTTP_SEE_OTHER                 303
#define HTTP_NOT_MODIFIED              304
#define HTTP_TEMPORARY_REDIRECT        307
#define HTTP_PERMANENT_REDIRECT        308
#define HTTP_BAD_REQUEST               400
#define HTTP_UNAUTHORIZED              401
#define HTTP_FORBIDDEN                 403
#define HTTP_NOT_FOUND                 404
#define HTTP_NOT_ALLOWED               405
#define HTTP_REQUEST_TIME_OUT          408
#define HTTP_CONFLICT                  409
#define HTTP_LENGTH_REQUIRED           411
#define HTTP_PRECONDITION_FAILED       412
#define HTTP_REQUEST_ENTITY_TOO_LARGE  413
#define HTTP_REQUEST_URI_TOO_LARGE     414
#define HTTP_UNSUPPORTED_MEDIA_TYPE    415
#define HTTP_RANGE_NOT_SATISFIABLE     416
#define HTTP_MISDIRECTED_REQUEST       421
#define HTTP_TOO_MANY_REQUESTS         429
#define HTTP_CLOSE                     444
#define HTTP_NGINX_CODES               494
#define HTTP_REQUEST_HEADER_TOO_LARGE  494
#define HTTPS_CERT_ERROR               495
#define HTTPS_NO_CERT                  496
#define HTTP_TO_HTTPS                  497
#define HTTP_CLIENT_CLOSED_REQUEST     499
#define HTTP_INTERNAL_SERVER_ERROR     500
#define HTTP_NOT_IMPLEMENTED           501
#define HTTP_BAD_GATEWAY               502
#define HTTP_SERVICE_UNAVAILABLE       503
#define HTTP_GATEWAY_TIME_OUT          504
#define HTTP_VERSION_NOT_SUPPORTED     505
#define HTTP_INSUFFICIENT_STORAGE      507

static const char* req_target[REQ_TYPE_NUM] = {"UNKNOWN", "POST", "GET", "HEAD", "PUT", "PATCH", "OPTIONS", "DELETE", "CONNECT", "TRACE"};

typedef struct req_header_s req_header_t;
struct req_header_s{
    int fd;
    struct http_fd_s *fds;
    struct http_socket_event_loop_s *hset;
};

/************     http_req_header.c       ***************/
void http_request_header_handler(req_header_t * header);
struct requestContext {
    int fd;
    dts home;
    dts reqType;
    dts reqPath;
    dts version;
    dts clientAddr;
    dts head;
    struct http_fd_s *fds;
    struct req_header_s *rh;
    Leader req_head_params;
};
#endif //HTTPSERVER_HTTP_REQUEST_H
